<?php
namespace Common\Model;

/**
 * 客栈表
 * @modify zhangzhen 2016-12-22 创建
 */

Class RoomSynModel extends \Common\Model\BaseModel
{
    protected $trueTableName = 'tb_room_syn';
    
    /**
     * 客栈同步表
	 * @modify zhangzhen 2016-12-27  添加房间同步信息  
     * @param  string   $masterentityId        集群id
     * @param  integer  $masterbuildinfoId     楼栋号
     * @param  integer  $masterfloorinfoId     楼层号
	 * @param  string   $masterroominfoId      集群下的房间id
     * @param  string   $hotelId               酒店id    
     * @param  string   $roominfoId            房间id 
     * @return boolean 添加结果
     */
    public function addInfo($masterentityId, $masterbuildinfoId, $masterfloorinfoId, $masterroominfoId, $hotelId, $roominfoId) {
        $data = array(
            'masterentity_id' => $masterentityId,
            'masterbuildinfo_id' => $masterbuildinfoId,
            'masterfloorinfo_id' => $masterfloorinfoId,
			'masterroominfo_id' => $masterroominfoId,
            'hotelentity_id' => $hotelId,
            'roominfo_id' => $roominfoId,
        );
        $id = $this->add($data);
        return $id === false ? false : $id;
    }
	/**
     * 删除房间同步记录
	 * @modify zhangzhen 2016-12-27  添加房间同步信息  
     * @param  string   $roomId       房间ID
     * @return boolean 添加结果
     */
    public function deleteInfo($roomIds) {
        if (is_array($roomIds)) {
            $roomIds = implode(',', $roomIds);
        }
        if (strpos($roomIds, ',') !== false) {
            $option['roominfo_id'] = array('in', $roomIds);
        } else {
            $option['roominfo_id'] = $roomIds;
        }
        $result = $this->where($option)->delete();
        return $result === false ? false : true;
    }
	
    /**
     * 更新房间数据
     * @modify trainyao 2016-01-04   创建
     * @param  string   $masterentityId        集群id
     * @param  integer  $masterbuildinfoId     楼栋号
     * @param  integer  $masterfloorinfoId     楼层号
     * @param  string   $masterroominfoId      集群下的房间id
     * @param  string   $hotelId               酒店id    
     * @param  string   $roominfoId            房间id 
     * @return boolean 执行结果
     */
    public function editInfo($masterentityId, $masterbuildinfoId, $masterfloorinfoId, $masterroominfoId, $hotelId, $roominfoId) {
        $option = array(
            'roominfo_id' => $roominfoId,
        );
        $data = array(
            'masterentity_id' => $masterentityId,
            'masterbuildinfo_id' => $masterbuildinfoId,
            'masterfloorinfo_id' => $masterfloorinfoId,
            'masterroominfo_id' => $masterroominfoId,
            'hotelentity_id' => $hotelId,
        );
        return $this->where($option)->save($data) === false ? false : true;
    }

    public function getInfoByMasterRoomId($masterRoomId){
        $where = array(
            'masterroominfo_id' => $masterRoomId,
        );
        return $this->where($where)->find();
    }

    public function getInfoByRoomId($roomId){
        $where = array(
            'roominfo_id' => $roomId,
        );
        return $this->where($where)->find();
    }
}
